package com.apes.scm.warning;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.apes.framework.query.ApesDao;
import com.apes.framework.query.SqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: apes-server
 * @description 异业合作警告
 * @author: czs
 * @create: 2021-05-28 15:41
 **/
@Component
public class PriceWarningDao extends ApesDao {
    @Autowired
    SqlService sqlService;
    public JSONArray findAllCrossPriceItems() {
        StringBuffer sf = new StringBuffer();
        sf.append(" SELECT A.ID CROSS_ID,A.NAME CROSS_NAME,A.PARTNER_ID,A.COMPANY_ID,B.NAME SERVE_NAME,C.CROSS_SERVE SERVE_ID, ");
        sf.append(" (SELECT F.NAME FROM MAS_PARTY_ROLE D, MAS_PARTY F WHERE A.COMPANY_ID = D.ID AND D.PARTY_ID = F.ID) COMPANY,");
        sf.append(" TO_CHAR(C.START_DATE,'yyyy-mm-dd hh24:mi:ss') START_DATE,TO_CHAR(C.END_DATE,'yyyy-mm-dd hh24:mi:ss') END_DATE,");
        sf.append(" (SELECT F.NAME FROM MAS_PARTY_ROLE D, MAS_PARTY F WHERE A.PARTNER_ID = D.ID AND D.PARTY_ID = F.ID) PARTNER_NAME");
        sf.append(" FROM MAS_CROSS_DIC A ,MAS_CROSS_ICS B LEFT JOIN Z_CROSS_CL039_EXEC C ON B.ID = C.CROSS_SERVE  ");
        sf.append(" WHERE A.ID = B.CROSS_DIC AND B.VALID = 1 AND (END_DATE <(SYSDATE+15)OR END_DATE IS NULL)  ");
        sf.append(" ORDER BY START_DATE ");
        return toJSONArray(find(sf.toString(),new JSONObject()));
    }

    public JSONArray findAllCrossPriceNum() {
        StringBuffer sf = new StringBuffer();
        sf.append(" SELECT COUNT(*) COUNT");
        sf.append(" FROM MAS_CROSS_DIC A ,MAS_CROSS_ICS B LEFT JOIN Z_CROSS_CL039_EXEC C ON B.ID = C.CROSS_SERVE  ");
        sf.append(" WHERE A.ID = B.CROSS_DIC AND B.VALID = 1 AND (END_DATE <(SYSDATE+15)OR END_DATE IS NULL)  ");
        return toJSONArray(find(sf.toString(), new JSONObject()));
    }
}
